﻿
var connection = require("../../app_modules/dbAccess/mongoConfig.js");
var mongoose = require('mongoose');
//var db = mongoose.connect(connection.getConnectionString("")); //连接test数据库
var db = mongoose.createConnection(connection.getConnectionString(""));

var Schema = mongoose.Schema; //创建模型【骨架模板】
var productSchema = new Schema({
    title: String,
    description: String,
    filename: String,
    createDate: Date,
    images:[{
        filename: String,
        description: String,
        createDate: Date,
        width:Number,
        height:Number
    }],
    width:Number,
    height:Number
});

productSchema.methods.add = function (product, callback) {
    this.title = product.title;
    this.description = product.description;
    this.filename = product.filename;
    this.createDate = product.createDate;
    this.images = product.images;
    this.width=product.width;
    this.height=product.height;
    this.save(callback);
}


var product = db.model('products', productSchema);
module.exports = product;
